@use 'sass:map';

@use './shared' as *;
@use './design' as *;
@use './input.scss' as input;

$select: () !default;
$select: map.merge(
  (
    list-bg-color: get-css-var('bg-color-base'),
    list-b-color: get-css-var('border-color-light-2'),
    list-border: get-css-var('border-shape') get-css-var('select-list-b-color'),
    list-radius: get-css-var('radius-base'),
    list-shadow: get-css-var('shadow-base'),
    check-color: get-css-var('color-primary-base'),
    empty-color: get-css-var('content-color-placeholder'),
    filter-height: 32px,
    filter-divider: get-css-var('border-shape') get-css-var('border-color-light-2')
  ),
  $select
);

.#{$namespace}-select {
  &-vars {
    @include define-preset-values('select', $select);
  }

  @include basis;

  display: inline-flex;
  width: 100%;
  cursor: pointer;

  &--filterable {
    cursor: text;
  }

  @include input.handler(#{&}__selector);

  &__selector {
    cursor: inherit;
  }

  &--disabled {
    cursor: not-allowed;
  }

  &--multiple &__selector {
    @include define-css-var('input-v-padding', 2px);

    height: auto;
    min-height: get-css-var('input-height');
  }

  &__control,
  &__input {
    user-select: none;
  }

  &__control {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 40px;
  }

  &--multiple &__control {
    flex-wrap: wrap;
    min-height: 0;
    margin: -1px 0;
  }

  &--responsive &__control {
    flex-wrap: nowrap;
  }

  &__tags {
    display: inline-flex;
    flex: 0 0 auto;
    width: auto;
    max-width: 100%;
  }

  &__tag {
    max-width: 100%;
    height: calc(get-css-var('input-height') - 8px);
    margin: 2px 4px;
    margin-inline-start: 0;
    pointer-events: auto;
    cursor: pointer;

    // &--preview {
    //   pointer-events: none;
    //   opacity: 50%;
    // }

    // &--deleted {
    //   text-decoration: line-through;
    // }
  }

  &--disabled &__tag {
    cursor: not-allowed;
  }

  &__selector--small &__tag {
    & > span {
      height: 100%;
      line-height: 1;
    }
  }

  &__control &__tag + &__tag {
    margin-inline-start: 0;
  }

  &__rest-tip {
    max-width: 100%;
  }

  &__anchor {
    position: relative;
    display: inline-block;
    max-width: 100%;
    height: calc(get-css-var('input-height') - 8px);
    margin: 2px 4px;
    margin-inline-start: 0;
  }

  &__input {
    position: absolute;
    width: 100%;
    height: 100%;
    padding: 0;
    color: inherit;
    pointer-events: none;
    user-select: auto;
    background-color: transparent;
    border: 0;
    outline: 0;

    &--multiple {
      position: relative;
      min-width: 1px;
    }

    &--visible {
      pointer-events: auto;
    }

    &::placeholder {
      color: get-css-var('input-placeholder-color');
    }
  }

  &__device {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    white-space: pre;
    visibility: hidden;
    opacity: 0%;
  }

  &__selected,
  &__placeholder {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
  }

  &__selected--placeholder,
  &__placeholder {
    color: get-css-var('input-placeholder-color');
  }

  &--multiple#{&}--filter &__placeholder {
    margin-left: -4px;
  }

  &__popper {
    min-width: 98px;
  }

  &__list {
    display: flex;
    flex-direction: column;
    width: 100%;
    user-select: none;
    background-color: get-css-var('select-list-bg-color');
    border: get-css-var('select-list-border');
    border-radius: get-css-var('select-list-radius');
    box-shadow: get-css-var('select-list-shadow');

    .#{$namespace}-native-scroll__wrapper {
      padding: 5px 0;
    }

    &--with-extra {
      padding: 5px 0;

      .#{$namespace}-native-scroll__wrapper {
        padding: 0;
      }
    }
  }

  &__filter {
    padding: 0 6px;
    border-bottom: get-css-var('select-filter-divider');
  }

  &__options {
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;

    &--has-check {
      .#{$namespace}-option {
        justify-content: space-between;
      }
    }
  }

  &__group {
    padding: get-css-var('option-label-v-padding') get-css-var('option-label-h-padding');
  }

  &__label {
    flex: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    &--group {
      font-size: get-css-var('option-group-font-size');
      color: get-css-var('option-group-color');
    }
  }

  &__check {
    color: get-css-var('select-check-color');
  }

  &__selector--focused &__arrow {
    transform: rotate(180deg);
  }

  &__empty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 3px 16px;
    color: get-css-var('select-empty-color');
    white-space: nowrap;
    cursor: default;
    background-color: get-css-var('select-list-bg-color');
  }

  &__clear {
    @include clean-button;
  }
}
